package Before826.luckycard;

import java.util.Random;
import java.util.Scanner;

public class method {
    private user[] users = new user[5];
    private Integer usernumber =0 ;
    private Integer lguser =1;
    Scanner input = new Scanner(System.in);
    //选择菜单
    public  void choice() {   System.out.println("*****欢迎进入奖客富翁系统*****");
        System.out.println("         1.注册");
        System.out.println("         2.登录");
        System.out.println("         3.抽奖");
        System.out.println("**************************");
        System.out.print("请选择菜单:");
        Scanner scanner = new Scanner(System.in);
        int number = scanner.nextInt();
        switch (number){
            case 1:
                regise(usernumber);
                break;
            case 2:
                login(users);
                break;
            case 3:
                cj(users,lguser);
                break;
            default:
                System.out.println("您的输入有误");
        }
    }
    //注册
    public void regise(Integer usernumber){
        Scanner scanner = new Scanner(System.in);
        System.out.println("[奖客富翁系统:注册]");
        System.out.println("请填写个人注册信息:");
        no:for (int i = 1; i < 7; i++) {
            if (usernumber == 5) {
                System.out.println("注册用户已到上限,请登录抽奖");
                break no;
            }
            System.out.print("用户名:");
            String username = scanner.next();
            System.out.print("密码:");
            String password = scanner.next();
            System.out.println();
            Random rand=new Random();
            int card=rand.nextInt(9);
            user user = new user(username, password, card);
            users[usernumber]=user;
            System.out.println("注册成功,请记好您的会员卡号");
            System.out.println("用户名     密码     会员卡号");
            System.out.println(username +"   "+password+"   "+card);
            System.out.print("是否要继续注册?(y/n)");
           for (int j = 0; j < 4; j++) {
                String answer = scanner.next();
                if (answer.equalsIgnoreCase("n") || j ==3) {
                    break no;
                }
                if (answer.equalsIgnoreCase("y")) {
                    break;
                }
                if (!answer.equalsIgnoreCase("y") && !answer.equalsIgnoreCase("n") ) {
                    System.out.println( "请重新输入" );
                }
            }

            usernumber++;
        }
    }
    //登录
    public void login(user[] users){
        System.out.println("[奖客富翁系统:登录]");
        Scanner scanner = new Scanner(System.in);

        out:for (int i = 0; i <3 ; i++) {
            System.out.print("请输入用户名:");
            String username1 = scanner.next();
            System.out.print("请输入密码:");
            String password1 = scanner.next();
            System.out.println();
            for (int j = 0; j < 5; j++) {
                if(users[j].getAdmin().equals(username1)  && users[j].getPassword2().equals(password1)){
                    System.out.println("欢迎您:"+username1);
                    lguser = j;
                    break out;
                }
            }
            System.out.println("请重新输入:");
        }
    }
    //抽奖

    public void cj( user[] users,Integer lguser){
        System.out.println("[奖客富翁系统:抽奖]");
        Random rand = new Random();
        int[] luckycard = new int[5];
        for (int i = 0; i < 5; i++) {
            luckycard[i] = rand.nextInt(9);
        }
        System.out.println("本日的幸运数字为:" + luckycard[0]+luckycard[1]+ luckycard[2]+ luckycard[3]+ luckycard[4]);
        for (int i = 0; i < 6; i++) {
            if (i == 5) {
                System.out.println("抱歉,您不是今日幸运会员.");
            }
            if (users[lguser].getCard1() == luckycard[i]) {
                System.out.println("恭喜!您是本日幸运会员");
                break;
            }
        }
    }
    //继续吗
    public void cont(){
        Scanner scanner = new Scanner(System.in);
        for (int i = 0; i < 4; i++) {
            System.out.print("继续吗:(y/n)");
            String A = scanner.next();
            if (!A.equalsIgnoreCase("y")  && !A.equalsIgnoreCase("n") ) {
                System.out.println( "请重新输入" );
            }
            if(A.equalsIgnoreCase("y")){
                choice();
            }
            if(A.equals("n") || i ==3){
                System.out.println("系统退出,谢谢使用!");
            }
        }
    }

}
